terminal — Home

Terminal

Parent Note (Up)
Next Note

Introduction

For a quick run down of how to customise and set up your terminal:
you're missing out on a better terminal experience

Step 1 - The Terminal Application

To begin with I installed iTerm, in order to bulk up the convenient features. Essentially, it makes the terminal feel less like working with an old school computer, and more like working on an application, with features like easy copy-paste, search, split panes etc.
iTerm webiste
After downloading, I installed simply by clicking on the application in the downloads tab of the dock, and followed the dialogue box instructions.

Step 2 - The Unix Shell (Terminal Interface)

The next thing for me to do is to pick the unix shell that I want iTerm to use. This is going to define the interface that the terminal will have, and how I can communicate with it. Most of this will not make too much of a difference to the level at which I code and execute code right now. But a little way down the line, a marginally better supported unix shell is better. And so I will use zsh over bash.
To find out more about unix shells, read this:
what is the shell?

To install zsh, I follow these steps:
- Check zsh version (if present) by typing and running "zsh --version" on iTerm2.
- Install/update zsh by typing and running "brew install zsh zsh-completions".
- Check version again (search online to see that it's recent enough).
- Check current default shell by typing and running "echo $SHELL".
- Set zsh as default shell by typing and running "chsh -s $(which zsh)".
- Check current default shell again for "/bin/zsh".

zsh --version
brew install zsh zsh-completions
echo $SHELL
chsh -s $(which zsh)

If the above doesn't work, an easier workaround through the mac UI is:
1. Go to System Preferences.
2. Click on "Users & Groups".
3. Click the lock to make changes.
4. Right click the current user -> Advanced options.
5. Change the login shell to /bin/zsh in the dropdown.
6. Open a new terminal and verify with "echo $SHELL".

echo $SHELL

Step 3 - Installing a Framework

To make either of the above steps really useful to me as a human, who is clueless about my terminal, it helps to have a framework which improves the interface and comes with clean plugins. While there are again multiple options, the recommended one is "oh my zsh", which can also be re-explored at a later stage.
oh my zsh
We install oh my zsh by typing and running the below command on iTerm2:

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh"

Every time I open iTerm2, it will now automatically use the zsh shell with the oh my zsh interface

Step 3.1 - Plugins in the Framework

ZSH on its own doesn't customise the terminal to a a satisfactory extent. In order to install these plugins that allow us to make the terminal a lot more human friendly, we must follow these steps:

Create a .zshrc file (contains customisations)
- where is the .zshrc file
- Open iTerm2
- In the main directory (where it just shows ->~) type in and enter "touch ~/.zshrc"
- In the finder application go to the home directory (contains Downloads, Music, Movies, Pictures, Public). This can be done by going to any of those subfolders and using "⌘ +up" to go to parent folder
- Use "⌘ +Shift+." to show hidden files
- Edit .zshrc in visualstudio to add plugins

To decide which plugins to use we can use this link as reference
Currently I have installed only syntax-highlighting & autosuggestions, and will install more if they seem useful later on. To install them, I follow the github links listed at the link.
syntax highlighting
- Read the install.md file.
- Used the syntax "brew install zsh-syntax-highlighting" in terminal.
- Copied the suggested line (suggested by brew installation) into the .zshrc file.

auto suggestions
- Read the install.md file.
- Used the syntax "brew install zsh-autosuggestions" in terminal.
- Copied the suggested line (suggested by brew installation) into the .zshrc file.

Step 4 - Setup a Theme

To make the terminal more legible and easy to navigate, we put in place a nice and convenient theme.
customise iTerm2 with zsh and powerlevel10k

First we put in place a different color scheme which might stand out more.
- Go to [https://github.com/QuentinWatt/dark-flat-iterm-colors](https://github.com/QuentinWatt/dark-flat-iterm-colors) and download flat-colors.itermcolors.
  - Instructions on how to download a single file from github [https://stackoverflow.com/questions/4604663/download-single-files-from-github](https://stackoverflow.com/questions/4604663/download-single-files-from-github).
- Go to iTerm2 windows and from the iTerm2 tab (near apple logo) select "Preferences".
- Go to the "Profiles" tab, "Colors" subtab.
- From the "Color Presets" dropdown select "Import" & select the downloaded file.
- Then from the same dropdown select "flat-colors".

Then we clone powerlevel10k, which is the theme which we will be applying.
- First we use the terminal to run the following command to clone the git repository for powerlevel10k (download and install).

git clone https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k

- In .zshrc file we edit the theme line so that it reads ZSH_THEME="powerlevel10k/powerlevel10k".
- Then close iTerm2 (even right click iTerm2 in dock and quit it) & reopen it, so that powerlevel10k installation wizard opens up.
- Answer the questions, ensuring that it's able to configure the right symbols and shapes.
- Then select appearance preferences. My preferences are:
  - Rainbow
  - Unicode
  - 24hr format
  - Angled
  - Sharp
  - Flat
  - One line
  - Sparse
  - Many icons
  - Concise
  - Enable transient prompt
- At this point save and close .zshrc file before allowing it to apply changes to the file.
- To redo configuration at any point we can run "p10k configure" in terminal.

To then make sure that these updates flow to Visual Studio:
- Close & quit visual studio. Then reopen it.
- In the terminal, click the dropdown next to the + button & select zsh.
- The UI of the terminal might not look right.
- From the "Code" tab near the apple logo, select "Preferences"->"Settings".
- Search for "settings.json" and click on "Edit in settings.json".
- Before the "[json]" field, add/edit a line for: "terminal.integrated.fontFamily": "'MesloLGS NF'"
This should also be the font in regular terminal if ever that is used again

Now that terminal (iTerm2) is set up, we can move forward to the last few stages of setup. Going forward, I'm likely to refer to the iTerm2+ZSH+OhMyZSH setup as just "terminal".

Additional but Useful (Python)

Now would also be a good time to install python the right way, since python is something we'll use a lot of. Even though we won't be doing much heavy coding yet, it helps to have python installed, and to have the environment (VS Code + terminal) set up for it right away.
install python 3
- In the .zshrc file, add the line "export PATH="/usr/local/opt/python/libexec/bin:$PATH" at the end.
- Save and close the file.
- Restart iTerm2.
- Run "python --version" & "python3 --version" to check which version of python you have right now.
- Then run "brew install python".
- Check the version of python again, and it should have updated now with "python3 --version". If not yet updated, quit iTerm and check again.

python --version
python3 --version
brew install python
python3 --version

Shell Scripting

The language in which commands are entered into the terminal is known as shell script. There are multiple variants of shell script which can be used, and ones terminal can be setup in accordance with the same.
In the early stages of development, one need not be an expert in shell script. For the most part, tutorials, installation guides etc will provide one with the necessary shell script commands. However, as you begin to take on bigger projects, it might be useful to pick up some shell scripting to improve one's pace and understanding of development.

End of Note

Notes mentioning this note